﻿<!--#include file="h.asp"--><%
'
'	七色虎建站系统
'	友链页面
'	2012.4.5

Sub main
	'友链配置
	linkActive=linkAct
	If linkStyle<>"1" Then linkStyle = 0'排版
	If linkJump<>"1" Then linkJump = 0'跳转
	If linkActive<>"0" Then linkActive = 1'审核方式
	If Not ifNum(linkNum) Then linkNum = 30'友链每页条数
	If Not ifNum(linkShort) Then linkShort = 2'简称字数
	If Not ifNum(linkHide) Then linkHide = 10'无连入自动隐藏天数
	If Not ifNum(linkDelete) Then linkDelete = 500'无连入自动删除天数

	Dim act,rs,sql,rss,sqll,class_,id,body_,br
	' Dim linkNum,linkActive,active,linkindex,links
	Dim PageSize,Count,page,i,pagecount
	Dim classid,name,namt,url,jian
	body_ = ""
	id=getN("id",1)
	act=request.QueryString("act")
	if act="" then
		hu.title = "友情链接"
		body_ = body_ & "[div=nav]※动态友链:[/div]"
		Sql="select id,name,classid from 74hu_link where active=0 and del=0 and datediff('d', HU_time, '"&time_now&"')<"&linkHide&" order by HU_time desc,id desc"
		Set rs = Server.CreateObject("ADODB.Recordset")
		rs.open sql, hu.db, 1, 1
		If Not rs.eof Then
			PageSize=linkNum
			count = rs.recordcount
			page=getN("page",1)
			if page<=0 then page=1
			pagecount=(count+pagesize-1)\pagesize
			if page>pagecount then page=pagecount
			rs.move(pagesize*(page-1))
			For i=1 To PageSize
				If rs.eof Then Exit For
				If i Mod 2 = 0 Then
					class_="even"
				Else
					class_="odd"
				End If
				body_ = body_ & "[div="&class_&"]"&i+(page-1)*PageSize&"."&hu.url("link.asp?act=view&amp;id="&rs("id")&"&amp;class="&rs("classid"),nowml(rs("name")))&"[/div]"
				rs.moveNext
			Next
			body_ = body_ & showPage("link.asp", "", page, pagecount)&""
		Else
			body_ = body_ & "暂时没有友链！<br/>"
		end if
		rs.close
		body_ = body_ & "[div=nav]※网站分类:[/div]"
		if linkStyle=0 then
			Set rs= hu.conn("select classid,class from 74hu_linkc order by pid asc")
			if rs.eof then
				body_ = body_ & "暂无分类<br/>"
			else
				do while not rs.eof
					class_ = rs("classid")
					set rss=hu.conn( "select top 4 id,namt from 74hu_link where active=0 and del=0 and classid="&class_&" order by HU_time desc,id desc")
					body_ = body_ & "【" & hu.url("link.asp?act=list&amp;class="&class_, nowml(rs("class")))&"】"
					If rss.eof then
						body_ = body_ & "暂时还没有<br/>"
					Else
						for i=1 to 6
							if rss.EOF then Exit for
							body_ = body_ & hu.url("link.asp?act=view&amp;class="&class_&"&amp;id="&rss("id"), nowml(rss("namt")))&" "
							rss.Movenext
						Next
						body_ = body_ & "<br/>"
					End if
					rss.close
					set rss=nothing
					rs.movenext
				loop
			end if
		else
			Set rs=hu.conn("select br,classid,class from 74hu_linkc order by pid asc")
			if not (rs.bof and rs.eof)  then
				While Not rs.eof
					'If Rs.Eof Then exit For
					if rs("br")="1" then
						br="<br/>"
					else
						br=""
					end if
					body_ = body_ & hu.url("link.asp?act=list&amp;class="&rs("classid"), nowml(rs("class")))&" "& br &""
					rs.MoveNext
				Wend
			end if
		end if
		body_ = body_ & hu.url("link.asp?act=add","&gt;&gt;友链合作申请")&"<br/>"&hu.url("link.asp?act=wait","待审网站")&_
			"-" & hu.url("link.asp?act=query", "查找回链")
	elseif act="go" then
		' On Error Resume Next
		Dim yourip,sss,ips,cache_ip,one_ip,all_s,k_ip,i_ip,del_time,ip_time,temp_s
		Server.ScriptTimeOut=9999999
		yourip=Request.ServerVariables("HTTP_X_UP_CALLING_LINE_ID")
		if yourip="" then yourip=Request.ServerVariables("HTTP_X_FORWARDED_FOR")
		if yourip="" then yourip=Request.ServerVariables("REMOTE_ADDR")
		sss=180
		ips=500
		cache_ip=Application("cache_ip")
		if cache_ip="" then cache_ip="|"
		one_ip=split(cache_ip,"|")
		all_s=ubound(one_ip)
		for k_ip=0 to all_s
			if yourip=one_ip(k_ip) then
				i_ip=k_ip:ip_time=one_ip(k_ip+1):Exit for
			else
				i_ip=0:ip_time="2000-10-10 10:10:10"
			end if
		next
		del_time=DATEDIFF("s",ip_time,time_now)
		if i_ip<all_s and sss>del_time then r ""&http_path&"?aid=index"
		if all_s>ips*2 Then
			Application.Lock
			Application("cache_ip")="|"
			Application.UnLock
		else
			if i_ip=0 then
				temp_s=cache_ip&yourip&"|"&time_now&"|"
			else
				Dim text_1,num_1,num_2,num_3,num_4,text_2,text_3,text_4
				text_1="|"&yourip&"|"&ip_time&"|"
				num_1=len(cache_ip)
				num_2=len(text_1)
				num_3=instr(cache_ip,text_1)
				num_4=num_1-num_2-num_3+1
				text_2=left(cache_ip,num_3)
				text_3=right(cache_ip,num_4)
				text_4=yourip&"|"&time_now&"|"
				temp_s=text_2&text_4&text_3
			end if
			Application.Lock
			Application("cache_ip")=temp_s
			Application.UnLock
		end if
		hu.conn("update 74hu_link set hu_in=hu_in+1,hu_time='"&time_now&"' where id="&id)
		hu.redirect ""&http_path&"?aid=index"
	elseif act="view" then
		Set rs= hu.conn("select name,url,jian from 74hu_link where id="&id)
		If Not rs.eof Then
			hu.conn("update 74hu_link set hu_out=hu_out+1,outtime='"&time_now&"' where id="&id)
		Else
			hu.redirect ""&http_path&"?aid=index"
		End If
		If linkJump=0 Then
			hu.title = nowml(rs("name"))
			url = noubburl(rs("url"))
			hu.autoredirect = url
			body_ = body_ & "[div=nav]-" &hu.url("?aid=index","首页") & "-" & hu.url("link.asp", "友链") & "-查看网站[/div]"
			body_ = body_ & "站名："&nowml(rs("name"))&"<br/>介绍："&nowml(rs("jian"))&"<br/>- > <a href="""&url&""">访问网站</a><br/>"
			body_ = body_ & "回链：http://"&wapUrl&"/link.asp?act=go&amp;id="&id&"<br/><br/>"
		Else
			hu.redirect nourl(rs("url"))
		End If
	elseif act="post" then
		classid=getData("classid")
		name=getD("name","")
		namt=getD("namt","")
		url=LCase(getD("url",""))
		jian=getD("jian","")
		if name="" or namt="" or url="" or jian="" or classid="" or isnumeric(classid)=false then
			rupt "错误","各项都要填写,不能为空，"&hu.url("link.asp?act=post", "返回")
		else
			If 0<hu.conn("select count(id) from 74hu_link where url='"&url&"'")(0) Then rupt "错误", "请不要重复提交！"
			hu.conn("insert into 74hu_link ([name],[namt],[url],[classid],[jian],[active])values('"&name&"','"&namt&"','"&url&"',"&classid&",'"&jian&"',"&linkActive&")")
		end if
		hu.title = "申请友链成功"
		hu.autoredirect = http_path&"link.asp?act=you&amp;"&sid_str
		body_ = body_ & "申请友链成功,"& hu.url("link.asp?act=you","查看回链")
	elseif act="list" then
		classid=request.QueryString("class")
		if classid="" or IsNumeric(classid)=false then
			hu.redirect ""&http_path&"?aid=index"
		else
			Set rss=hu.conn("select top 1 class from 74hu_linkc where classid="&classid)
			if not rss.eof then
				name=rss("class")
				hu.title = name& "网站"
				body_ = body_ & "[div=nav]-" & hu.url("?aid=index", "首页")&"-" & hu.url("link.asp", "友链")&"-"&name&"网站[/div]"
				sql = "select classid,id,name from 74hu_link where classid="&classid&" and active=0 and del=0 order by HU_time desc"
				Set rs = Server.CreateObject("ADODB.Recordset")
				rs.open sql, hu.db, 1, 1
				If Not rs.eof Then
					PageSize=15
					count = rs.recordcount
					page=getN("page",1)
					if page<=0 then page=1
					pagecount=(count+pagesize-1)\pagesize
					if page>pagecount then page=pagecount
					rs.move(pagesize*(page-1))
					For i=1 To PageSize
						If rs.eof Then Exit For
						If i Mod 2 = 0 Then
							class_="even"
						Else
							class_="odd"
						End If
						body_ = body_ &"[div="&class_&"]"&i+(page-1)*PageSize&"."&hu.url("link.asp?act=view&amp;class="&rs("classid")&"&amp;id="&rs("id"),nowml(rs("name")))&"[/div]"
						rs.moveNext
					Next
					body_ = body_ & showPage("link.asp", "act:list,class:"&classid, page, pagecount)&""
				Else
					body_ = body_ & "暂时没有添加！<br/>"
				end if
			end if
			rss.close
			set rss=nothing
			body_ = body_ & hu.url("link.asp","返回友链首页")&"<br/>"
		end if
	elseif act="you" then
		hu.title = "申请友链成功"
		Set rs = hu.conn("select top 1 id from 74hu_link order by id desc")
		body_ = body_ & "添加友链地址成功，"
		if int(linkActive)=1 then
			body_ = body_ & "请等待站长审核，审核通过后才会显示<br/>"
		else
			body_ = body_ & "你的友链已经显示出来!<br/>"
		End if
		body_ = body_ & "贵站返回我站的链接地址是:http://"&wapUrl&"/link.asp?act=go&amp;id="&Rs("id")&"<br/>网站名称:"&wapTitle&"<br/>"&hu.url("link.asp","返回友链首页")&"<br/>"
	elseif act="add" then
		hu.title = "申请友链"
		Dim formArray(6)
		formarray(0) = http_path&"link.asp?act=post||post||确定提交||网站名称:(3-6字)<br/>"
		formarray(1) = "input||name$$$$15$$7||<br/>网站简称:("&linkShort&"字)<br/>"
		formarray(2) = "input||namt$$$$15$$"&linkShort&"||<br/>网址:(需http://)<br/>"
		formarray(3) = "input||url$$http://$$15$$100||<br/>网站分类：<br/>"
		Set rs=hu.conn("select classid,class from 74hu_linkc order by classid desc")
		formarray(4) = ""
		do while not Rs.eof
			classid = rs("classid")
			formarray(4) = classid & "$$" & rs("class") & "||" & formarray(4)
			rs.movenext
		Loop
		formarray(4) = "select||classid$$"&classid&"||" & formarray(4) & "<br/>网站简介：(50字内)<br/>"
		formarray(5) = "input||jian$$暂时没有介绍…$$15$$100||<br/>"
		formarray(6) = "hidden||"&bbsSid&"$$"&sid&"||"
		body_ = body_ & hu.getForm(formarray) &"<br/>"&_
			"<br/>欢迎优秀WAP网站交换链接。"&_
			"<br/>1.合作原则:流量互补,双赢发展,"&linkHide&"天没流量首页自动隐藏。"&_
			"<br/>2.流程: "&_
			"<br/>1)提交网站，获取链接地址; "&_
			"<br/>2)将我站的链接放到贵站明显位置。"&_
			"<br/>3)我站人员3个工作日内审核网站，合适网站即可收录。"&_
			"<br/>"&_
			"<br/>申请友情链接前请先在您的网站上做好本站的链接："&_
			"<br/>网站名称："&wapTitle&_
			"<br/>做好我站链接后，我们会及时进行审核。<br/>"&_
			hu.url("link.asp", "返回友链首页")& "<br/>"
	elseif act="wait" then'待审
		hu.title = "待审友链"
		body_ =body_ & "[div=nav]-"&hu.url("?aid=index", "首页") & "-"& hu.url("link.asp", "友链")& "-待审友链[/div]"
		sql = "select classid,id,name from 74hu_link where active=1 and del=0 order by HU_time desc"
		Set rs = Server.CreateObject("ADODB.Recordset")
		rs.open sql, hu.db, 1, 1
		If Not rs.eof Then
			PageSize=15
			count = rs.recordcount
			page=getN("page",1)
			if page<=0 then page=1
			pagecount=(count+pagesize-1)\pagesize
			if page>pagecount then page=pagecount
			rs.move(pagesize*(page-1))
			For i=1 To PageSize
				If rs.eof Then Exit For
				body_ =body_ & ""&i+(page-1)*PageSize&"."&nowml(rs("name"))&"<br/>"
				rs.moveNext
			Next
			body_ =body_ & showPage("link.asp", "act:wait", page, pagecount)
		Else
			body_ =body_ & "暂时没有待审网站！<br/>"
		end if
		body_ =body_ & hu.url("link.asp", "返回友链首页")
	elseIf act="query" then'查回链
		a=getDD("a","")
		lnk=getD("link","")
		hu.title = "查找回链"
		body_ =body_ & "[div=nav]-"&hu.url("?aid=index", "首页") &"-"& hu.url("link.asp", "友链") & "-查找回链[/div]"
		If a="" Then
			Dim formArray2(2)
			formarray2(0) = http_path&"link.asp?act=query&amp;a=1||post||查找回链"
			formarray2(1) = "input||link$$$$15$$200||"
			formarray2(2) = "hidden||"&bbsSid&"$$"&sid&"||"
			body_ =body_ &  hu.getForm(formarray2)
		Else
			If lnk="" Then
				body_ =body_ & "网站不能为空"
			Else
				Set rs=hu.conn("select top 1 id,url,name,active from 74hu_link where url like '%" & lnk & "%'")
				If Not rs.eof Then
					body_ =body_ & "网址:"&nowml(rs("url"))&"<br/>站名:"&nowml(rs("name"))&"<br/>回链:http://"&wapUrl&"/link.asp?act=go&amp;id="&Rs("id")&"<br/>状态:"
					If rs("active")=1 Then
						body_ =body_ & "未审核"
					Else
						body_ =body_ & "已审核"
					End If
				Else
					body_ =body_ & "没有这个网站!"
				End If
			End If
		End If
		body_ =body_ & "<br/>" & hu.url("link.asp","返回友链首页")
	else
		body_ =body_ & hu.url("link.asp", "返回友链首页")
	end if
	set rs=nothing
	hu.body = comUbb(body_)
End Sub

%>